Tags: #◇Computer Science #◇CSOPESY #◇Operating Systems #◇CPU Scheduling #◇Quiz #◇Reviewer
CSOPESY Practice Quiz 2: CPU Scheduling (Weeks 6-8)
◇Overview
This quiz covers CPU Scheduling algorithms and Process Synchronization from Weeks 6 through 8. It is structured as a real exam format: Part I tests conceptual understanding with multiple choice questions, and Part II requires manual Gantt chart construction and metric computation.
Coverage:
- Note 06: CPU Scheduling (FCFS, SJF, SRTF, Priority, Round Robin, Dispatcher)
- Note 07: Synchronization Tools (Race Conditions, Mutex, Semaphores, Deadlock)
◇Part I: Problem Solving — CPU Scheduling Gantt Charts
Problem 1: FCFS and Non-Preemptive SJF
Given the following set of processes:
| Process | Arrival Time (AT) | Burst Time (BT) |
|---|---|---|
| P1 | 0 | 10 |
| P2 | 2 | 5 |
| P3 | 4 | 4 |
| P4 | 6 | 7 |
Solve for each algorithm:
- Draw the Gantt chart (execution timeline).
- Compute Completion Time (CT), Turnaround Time (TAT = CT - AT), and Waiting Time (WT = TAT - BT) for each process.
- Compute the Average Waiting Time.
Formulas:
Problem 2: SRTF and Round Robin (q = 3)
Use the same process table from Problem 1.
For Round Robin with quantum q = 3:
- Processes arriving at the same time a quantum expires join the queue BEFORE the preempted process is re-queued.
- Processes with the same remaining time: do not preempt (continue running the current process).
◇Problem Solving Answer Key — Gantt Charts & Metrics
Problem 1 Solution: FCFS
Gantt Chart:
Process Metrics:
| Process | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 10 | 10 | 10 | 0 |
| P2 | 2 | 5 | 15 | 13 | 8 |
| P3 | 4 | 4 | 19 | 15 | 11 |
| P4 | 6 | 7 | 26 | 20 | 13 |
Average Waiting Time: ms
Problem 1 Solution: Non-Preemptive SJF
Selection logic:
- t=0: Only P1 available → P1 runs (0→10).
- t=10: P2 (BT=5), P3 (BT=4), P4 (BT=7) all present → shortest is P3 (4) → P3 runs (10→14).
- t=14: P2 (5), P4 (7) → shortest is P2 (5) → P2 runs (14→19).
- t=19: Only P4 → P4 runs (19→26).
Gantt Chart:
Process Metrics:
| Process | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 10 | 10 | 10 | 0 |
| P2 | 2 | 5 | 19 | 17 | 12 |
| P3 | 4 | 4 | 14 | 10 | 6 |
| P4 | 6 | 7 | 26 | 20 | 13 |
Average Waiting Time: ms
Problem 2 Solution: SRTF (Preemptive SJF)
Event-by-event trace:
| Time | Event | Remaining Times | CPU |
|---|---|---|---|
| t=0 | P1 arrives | P1(10) | P1 |
| t=2 | P2 arrives (5) < P1 rem (8) → preempt P1 | P1(8), P2(5) | P2 |
| t=4 | P3 arrives (4) > P2 rem (3) → continue | P1(8), P2(3), P3(4) | P2 |
| t=6 | P4 arrives (7) > P2 rem (1) → continue | P1(8), P2(1), P3(4), P4(7) | P2 |
| t=7 | P2 finishes. Shortest: P3(4) | P1(8), P3(4), P4(7) | P3 |
| t=11 | P3 finishes. Shortest: P4(7) | P1(8), P4(7) | P4 |
| t=18 | P4 finishes. Only P1 left | P1(8) | P1 |
| t=26 | P1 finishes | — | — |
Gantt Chart:
Process Metrics:
| Process | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 10 | 26 | 26 | 16 |
| P2 | 2 | 5 | 7 | 5 | 0 |
| P3 | 4 | 4 | 11 | 7 | 3 |
| P4 | 6 | 7 | 18 | 12 | 5 |
Average Waiting Time: ms
Problem 2 Solution: Round Robin (q = 3)
Queue trace (format: [Queue] → Run → [Queue after]):
| Slice | Time | Process | Remaining After | Queue Before Next |
|---|---|---|---|---|
| 1 | 0→3 | P1 | P1(7) | [P2, P3*, P1] — P2 at t=2, P3 at t=3 |
| 2 | 3→6 | P2 | P2(2) | [P3, P4*, P1, P2] — P3 at t=4, P4 at t=6 |
| 3 | 6→9 | P3 | P3(1) | [P4, P1, P2, P3] |
| 4 | 9→12 | P4 | P4(4) | [P1, P2, P3, P4] |
| 5 | 12→15 | P1 | P1(4) | [P2, P3, P4, P1] |
| 6 | 15→17 | P2 | DONE (CT=17) | [P3, P4, P1] |
| 7 | 17→20 | P3 | P3(0) → DONE (CT=20) | [P4, P1] |
| 8 | 20→23 | P4 | P4(1) | [P1, P4] |
| 9 | 23→26 | P1 | P1(1) | [P4, P1] |
| 10 | 26→27 | P4 | DONE (CT=27) | [P1] |
| 11 | 27→28 | P1 | DONE (CT=28) | — |
Gantt Chart:
Process Metrics:
| Process | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 10 | 28 | 28 | 18 |
| P2 | 2 | 5 | 17 | 15 | 10 |
| P3 | 4 | 4 | 20 | 16 | 12 |
| P4 | 6 | 7 | 27 | 21 | 14 |
Average Waiting Time: ms
[!note] Takeaway
For this process set: SRTF achieves the best Avg WT (6.0 ms), followed by SJF (7.75 ms), FCFS (8.0 ms), and RR (13.5 ms). SRTF is optimal but requires preemption overhead and future burst knowledge.
◇References & Navigation
- Related Notes: ◇CSOPESY 06 - CPU Scheduling, ◇CSOPESY 07 - Synchronization Tools
- Previous Quiz: ◇[QZ] CSOPESY Practice Quiz 1 - OS Foundations
- Mock Exam: ◇[QZ] CSOPESY Midterm Mock Exam
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
Which CPU scheduling algorithm is provably optimal for minimizing average waiting time among all non-preemptive algorithms?
A CPU scheduler uses the exponential average formula to predict future CPU burst lengths. If , what is the behavior of this predictor?
Process P1 (burst = 10ms) is currently running. At time t=5, Process P2 arrives with a burst of 3ms. Under the Shortest Remaining Time First (SRTF) algorithm, what happens?
Which of the following is the primary drawback of FCFS scheduling in a mixed-workload environment?
In Priority Scheduling, a low-priority process has been waiting in the ready queue for an extremely long time and has never received the CPU. What technique prevents this indefinite starvation?
Round Robin with a very large time quantum (approaching infinity) behaves like which other scheduling algorithm?
The time it takes for the OS to stop the current process, save its state, load the next process's state, and hand control to it is called:
Two threads access a shared counter variable without synchronization. Thread A reads the value (5), Thread B reads the value (5), Thread A increments and writes (6), Thread B increments and writes (6). The final value is 6 instead of the expected 7. What problem does this illustrate?
A correct solution to the Critical Section Problem must satisfy three conditions. Which of the following is NOT one of them?
A mutex_lock() call on a mutex that is already held by another thread causes the calling thread to spin in a tight while-loop until the mutex is released. What is this behavior called?
A Counting Semaphore is initialized to the value 3. Three threads each call wait() (P-operation), acquiring it successfully. A fourth thread calls wait(). What happens to the fourth thread?
For a deadlock to occur, which of the following four necessary conditions must ALL be present simultaneously?
Process A holds Resource 1 and is waiting for Resource 2. Process B holds Resource 2 and is waiting for Resource 1. Which deadlock condition does this scenario directly demonstrate?
Which of the following scheduling criteria should be MINIMIZED to improve system performance?
A process is currently in the Running state and its time quantum expires. It has not finished its burst. Which state transition occurs next?